<script>
$(document).ready(function() {
	$('.selectProduct').click(function() {
		var codeProduct = $(this).attr('codeProduct');
		$('#add-product-model').html('');
		$.ajax({
			'url' : url+'/product_selection_modal/distribution/',
			'type' : 'POST',
			'data' : {
				'code' : codeProduct,
				'needProductsStock' : '<?php echo $needProductsStock;?>'
			},
			'success' : function(res){
				$('#add-product-model').html(res);
			}
		});
	});
	$('#searchProducts').click(function(e) {
		var code =  $('#code').val();
		var description =  $('#description').val();
		var needProductsStock =  $('#needProductsStock').val();
		$.ajax({
			'url': url + '/product_selection_modal/',
			'type': 'POST',
			'data': {
				'code': code,
				'description': description,
				'needProductsStock': needProductsStock
			},
			'success': function(res) {
				$('#add-product-model').html(res);
			}
		});
		$('#add-product-model').modal();
		return false;
	});

})


</script>
<h3>Buscador de productos</h3>
<div class="widget_wrap">
	<div class="form_container">
	    <ul>
			<li>
    			<div class="form_grid_12">
    				<div class="form_input">
        				<form id="listProducts">
        					<div class="form_grid_4 alpha">
								<input id="needProductsStock" name="needProductsStock" type="hidden" value="<?php echo $needProductsStock; ?>" />
        						<input id="code" name="code" type="text" value="<?php echo $code; ?>" />
        						<span class=" label_intro">Código</span>
        					</div>
        					<div class="form_grid_6 ">
        						<input id="description" name="description" type="text" value="<?php echo $description; ?>" />
        						<span class=" label_intro">Descripción</span>
        					</div>
        					<div class="form_grid_2 ">
        					<button id="searchProducts" class="btn_small btn_blue"><span>Buscar</span></button>
        					</div>
    					</form>
    					<span class="clear"></span>
    				</div>
    			</div>
			</li>
		</ul>
	</div>
    
	<div class="widget_content">
		<table id="" class="wtbl_list">
    		<thead>
        		<tr>
        			<th>Código</th>
        			<th>Descripción</th>
        		</tr>
    		</thead>
    		<tbody>
    		    <?php foreach ($products as $p) : ?>
                <tr class="tr_even selectProduct " codeProduct="<?php echo $p->code; ?>" style="cursor: pointer;">
        			<td><?php echo $p->code; ?></td>
        			<td><?php echo $p->description; ?></td>
        		</tr>
        		<?php endforeach; ?>
    		</tbody>
		</table>
	</div>
</div>